{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d3fdd34b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import torch\n",
    "import math\n",
    "\n",
    "def CountIOU(RecA, RecB):\n",
    "  xA = max(RecA[0], RecB[0])\n",
    "  yA = max(RecA[1], RecB[1])\n",
    "  xB = min(RecA[2], RecB[2])\n",
    "  yB = min(RecA[3], RecB[3])\n",
    "\n",
    "  # 计算交集部分面积\n",
    "  interArea = max(0, xB - xA + 1) * max(0, yB - yA + 1)\n",
    "\n",
    "  # 计算预测值和真实值的面积\n",
    "  RecA_Area = (RecA[2] - RecA[0] + 1) * (RecA[3] - RecA[1] + 1)\n",
    "  RecB_Area = (RecB[2] - RecB[0] + 1) * (RecB[3] - RecB[1] + 1)\n",
    "\n",
    "  # 计算IOU\n",
    "  iou = interArea / float(RecA_Area + RecB_Area - interArea)\n",
    "  return iou\n",
    "\n",
    "def box_ciou(b1, b2):\n",
    "    \"\"\"\n",
    "    输入为：    ----------\n",
    "    b1: tensor, shape=(batch, feat_w, feat_h, anchor_num, 4), xywh\n",
    "    b2: tensor, shape=(batch, feat_w, feat_h, anchor_num, 4), xywh\n",
    "    返回为：    -------\n",
    "    ciou: tensor, shape=(batch, feat_w, feat_h, anchor_num, 1)\n",
    "    \"\"\"\n",
    "# 求出预测框左上角右下角\n",
    "    b1_xy = b1[..., :2]\n",
    "    b1_wh = b1[..., 2:4]\n",
    "    b1_wh_half = b1_wh/2.\n",
    "    b1_mins = b1_xy - b1_wh_half\n",
    "    b1_maxes = b1_xy + b1_wh_half\n",
    "    # 求出真实框左上角右下角\n",
    "    b2_xy = b2[..., :2]\n",
    "    b2_wh = b2[..., 2:4]\n",
    "    b2_wh_half = b2_wh/2.\n",
    "    b2_mins = b2_xy - b2_wh_half\n",
    "    b2_maxes = b2_xy + b2_wh_half\n",
    "\n",
    "    # 求真实框和预测框所有的iou\n",
    "    intersect_mins = torch.max(b1_mins, b2_mins)\n",
    "    intersect_maxes = torch.min(b1_maxes, b2_maxes)\n",
    "    intersect_wh = torch.max(intersect_maxes - intersect_mins, torch.zeros_like(intersect_maxes))\n",
    "    intersect_area = intersect_wh[..., 0] * intersect_wh[..., 1]\n",
    "    b1_area = b1_wh[..., 0] * b1_wh[..., 1]\n",
    "    b2_area = b2_wh[..., 0] * b2_wh[..., 1]\n",
    "    union_area = b1_area + b2_area - intersect_area\n",
    "    iou = intersect_area / (union_area + 1e-6)\n",
    "\n",
    "    # 计算中心的差距\n",
    "    center_distance = torch.sum(torch.pow((b1_xy - b2_xy), 2), axis=-1)\n",
    "    # 找到包裹两个框的最小框的左上角和右下角\n",
    "    enclose_mins = torch.min(b1_mins, b2_mins)\n",
    "    enclose_maxes = torch.max(b1_maxes, b2_maxes)\n",
    "    enclose_wh = torch.max(enclose_maxes - enclose_mins, torch.zeros_like(intersect_maxes))\n",
    "    # 计算对角线距离\n",
    "    enclose_diagonal = torch.sum(torch.pow(enclose_wh,2), axis=-1)\n",
    "    ciou = iou - 1.0 * (center_distance) / (enclose_diagonal + 1e-7)\n",
    "    v = (4 / (math.pi ** 2)) * torch.pow((torch.atan(b1_wh[..., 0]/b1_wh[..., 1]) - torch.atan(b2_wh[..., 0]/b2_wh[..., 1])), 2)\n",
    "    alpha = v / (1.0 - iou + v)\n",
    "    ciou = ciou - alpha * v\n",
    "    return ciou"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b9e8445c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def drawIoU(RecA,RecB):\n",
    "    cv2.rectangle(img, (RecA[0], RecA[1]), (RecA[2], RecA[3]), (0, 255, 0), 5)\n",
    "    cv2.rectangle(img, (RecB[0], RecB[1]), (RecB[2], RecB[3]), (255, 0, 0), 5)\n",
    "    IOU = CountIOU(RecA, RecB)\n",
    "    font = cv2.FONT_HERSHEY_SIMPLEX\n",
    "    cv2.putText(img, \"IOU = %.2f\" % IOU, (130, 190), font, 1.2, (0, 0, 0), 2)\n",
    "    plt.subplot(1,2,1)\n",
    "    plt.imshow(img)\n",
    "    \n",
    "def drawCIoU(RecA,RecB):\n",
    "    a = torch.tensor(RecA, dtype=torch.float)  # tensor, shape=(batch, feat_w, feat_h, anchor_num, 4), xywh\n",
    "    b = torch.tensor(RecB, dtype=torch.float)\n",
    "    cv2.rectangle(img, (int(RecA[1]-RecA[3]/2), int(RecA[2]-RecA[4]/2)), (int(RecA[1]+RecA[3]/2), int(RecA[2]+RecA[4]/2)), (0, 255, 0), 5)\n",
    "    cv2.rectangle(img,(int(RecB[1]-RecB[3]/2), int(RecB[2]-RecB[4]/2)), (int(RecB[1]+RecB[3]/2), int(RecB[2]+RecB[4]/2)), (255, 0, 0), 5)\n",
    "    CIOU = box_ciou(a,b)\n",
    "    font = cv2.FONT_HERSHEY_SIMPLEX\n",
    "    cv2.putText(img, \"CIOU = %.2f\" % CIOU, (130, 190), font, 1.2, (0, 0, 0), 2)\n",
    "    plt.subplot(1,2,2)\n",
    "    plt.imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0747ffe7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x2065b273850>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAC7CAYAAACend6FAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAZ50lEQVR4nO3df3BU9b3/8ec72fwQCBAQDD+FVtCCt4IG649vGQtoUS9gO0O1ooJYEe1Fa71QtDrYsYy2Tm9/aW+HXlSYe60w3uuAFA0Mij8AgaBWhDQSBDRCIUR+pA0mm+T9/SOHNYGF/Npkk8PrwWT27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"metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "img = np.zeros((512, 512, 3), np.uint8)\n",
    "img.fill(255)\n",
    "RecA = [20, 20, 300, 300]   # x1,y1,x2,y2\n",
    "RecB = [310, 310, 430, 430]\n",
    "drawIoU(RecA,RecB)\n",
    "img = np.zeros((512, 512, 3), np.uint8)\n",
    "img.fill(255)\n",
    "RecA = [1,160, 160, 280, 280]   # x1,y1,x2,y2\n",
    "RecB = [1,370, 370, 120, 120]\n",
    "drawCIoU(RecA,RecB)\n",
    "plt.imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "41565594",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x2065b3bfb50>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAC7CAYAAACend6FAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAZ+UlEQVR4nO3de3BV5bnH8e+T7FzkHhDkfqkHVPBUhICiLWMFW7wBvWCtVEGsEduDtlYtWhzsVEdbp6e01p4OcxSh51hhPMcBqRoYFPUIComoCDES5BZhICC3Npjrc/7IYpvADrntZCcrvw+T2Wu/+11rv2/y7B9rr72yYu6OiIiES1KiByAiIvGncBcRCSGFu4hICCncRURCSOEuIhJCCncRkRBqtnA3s0lmlm9mBWY2t7meR6Qlqa6lrbDmOM/dzJKBT4CrgEJgI/ADd98a9ycTaSGqa2lLmmvPfSxQ4O6funsp8DwwpZmeS6SlqK6lzWiucO8H7Kl2vzBoE2nLVNfSZkSaabsWo63G8R8zywKyADp27Dj6/PPPb6ahiEBubu5Bd+/ZxM3UWdeg2paWs3PnTg4ePBirLpst3AuBA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UnBLNbfe2j6+Nydw4cPA9CtWzeSkpJiP5dDaVkpx48dJzk5mW7dugFE51VZWRmdV0ZGBmbWLGOW1iNWPUciEcyM8vJyzIzk5ORo3+PHj0dfD507d47WTqwaLysrIzk5maSkxO1DnhzbsWPHiEQidO3atc6aLikpwcxOex2XlJTwj3/8g44dO5Kent7qXxvac69DcXExc+bMobi4GHfn3XffZdq0aUyePJlrrrmGhx56iC+++AKA/Px85s+fj/uXf6Dns88+47777qOysrJZxnf06FFmzZrFpEmTmDx5MjNmzODgwYOnd3TYlbeLqVOmcu211zJlyhQefPBBysvLASgqKmL69OlMmjSJKVOmcPvtt3Ps2LFmGbO0HkVFRcyePTtaz9OnT2fv3qq/QfLcc8/x0ksvAVWvgwcffJApU6YwefJkrrrqKv72t79F63revHls3769xrYfe+wx3n///Radz6l27drFDTfcEK35u+++m+Li4ph93Z1jx47x4x//mD/84Q812j/++GO++93vct111zF16lQWLVrUbK/peFG416GsrIzNmzdTXl7OoUOHmDt3LldddRXZ2dm88sorHDlyhGeffTZaGB9//HGN9f/5z3+ydevWZhmbu/P0009z9OhRVqxYwSuvvEJqaipPPvlkjf9gAKiE4/OPM/7S8bz66qssXbqU1157jdWrV+Pu/PGPfyQ1NZW///3vrFy5kqNHj/LMM8+cvh0JjfLycubNm8fIkSPJzs7m1VdfpXv37vzud7+jsrKSPXv2sG/fPtydF198kfXr17No0SJWrVrFI488wuOPP86uXbsAyMvLO21n4JNPPom+o0yEyspKHnvsMQYPHkx2djZLly4lPz+fJUuWxOx/6NAhZs6cSX5+Prt37462l5aWcs899zB9+nSys7OZN28eCxYsoKCgoKWm0igK9wbIzs6mf//+3HHHHXTu3JkePXowb948XnjhBY4fP97o7Z48tFLbV20qKipYtWoVP/vZz+jduzddunRhzpw5rF27lpKSkpqdi2DAzgHMnj2bjIwMevfuzY9+9CNWrlxJSUkJb7zxBvfccw+9evWia9euzJkzh+zsbCoq9Pcowmrr1q3s37+f22+/nc6dO0eDfcSIEZSVlUX7lZWVsXjxYh5++GEGDRpEp06dmDhxItdccw3Lli1r0g5AY2u/PoqLi/noo4+488476datG7179+a2227jnXfeibntzp078/DDD3PXXXfVOOSyc+dOKisr+d73vkfXrl352te+xgUXXJDwdyV10TH3Bti4cSOTJk2KHoME6N69OydOnODEiRON2qa7s2jRoujb31N9+9vf5uabb455fO/k8cR+/fpFH+/duzeVlZWnF285dD2ra43j7IMGDeLtt9+OHm/v3bt39LF+/fpRWlraqDlJ21BUVETnzp1JS0uLtnXs2JFZs2bV6Ld3716OHz/OqFGjonVmZlx//fX8+te/5uc//3mjnr+srIz58+eTl5d32mMZGRk88cQT9OjRI+a6Jz8rqAj+GJbjlFNOEknRzwkOHjxIUlISAwcOjK538cUX8/vf/57i4mI6duxYY5tpaWl89atf5ZNPPqnR3qFDBw4ePMi+ffsYNGgQx44do7CwkNzcXG644YZGzb0lKNwbwN1rfMgSL9/85je58MILYz7Wv3//uD+fyJmcuiNRUVFBWloa6enpNdozMjKin9k0RiQS4ZZbbon52U5qaipdu3atdd2SkhLuuusuNhZsxHF2sINruZYkkohEIjz22GP06NGD5OTkGjtjXbp0qXG/Pvr06cPo0aPJysrikksuYdOmTWzcuJHrrruuQdtpaQr3Brjooov48MMPmTZtWvQFcPLsgdrOCCgqKqqzmN5++21Wr14d87Grr76a73znOzEfMzNSUlJq7GGXlZVFz3aoIQkqrILy8vLonlpJSUn0P6tIJHLaW/Hm+I9MWo+UlBQOHz4cPdMFqnZgPv30UwYPHhzt16NHD06cOMHOnTsZNmxYtN9bb73FsGHDorVWvQ4rKyupqKiIbjeW8vJyli9fzrZt2057rGvXrjz00EPRd5qnSktL4+GHH+b1E69zMzfTn/78B/9BKqnRd54lJSVEIhGKioro168fAJs3b+bcc8/lrLPOqvf3KRKJsGDBAj744AO2bt3KRRddBMC4cePqvY1EULg3wMSJE5k5cyZ5eXlccMEFAKxatYoxY8bQvXt3jh49SmFhIXv37qVv376UlpbywgsvcOWVV57xdLCRI0fSqVOnmI8NHTq01vWS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ZzU30eJrKzAaY2etmlmdmW8zs7qA9tFcaNLNkM9tkZiuD+6Gda0Oottv+z7tN17a7J+wLSAa2A18BUoEPgOGJHFMc5tQHGBUsdwY+AYYDvwXmBu1zgd8Ey8ODeacBQ4LvR3Ki59HAOd8DPAesDO6Hdq4N+J6otkPw827LtZ3oPfexQIG7f+rupcDzVF15r81y933u/l6wfBzIo+riUqG80qCZ9QeuBf6zWnMo59pAqu02/vNu67Wd6HCv11X22iozGwxcDLxLE6802IotAO4HKqu1hXWuDRHquaq2W/9cEx3u9brKXltkZp2A/6HqV9SPnalrjLY28T0ws+uAA+6eW99VYrS1ibk2QmjnqtqOvUqMtoTOtb6X/G0uobzKnpmlUFX8/+3u/xs07zezPu6+L0RXGrwcmGxm1wDpQBcz+y/COdeGCuVcVdttaK4J/rAiAnxK1QcQJz90GpHIMcVhTgYsARac0v4ENT+I+W2wPIKaH8R8Shv70CmYxxV8+aFTqOdaz++HajskP++2Wtut4Rt3DVWfum8Hfpno8cRhPl+j6u3Yh8D7wdc1QA+q/h7ntuC2e7V1fhnMPx+4OtFzaOS8q78AQj3XBnxPVNsh+Hm31drWb6iKiIRQoj9QFRGRZqBwFxEJIYW7iEgIKdxFREJI4S4iEkIKdxGREFK4i4iEkMJdRCSE/h8UwJgA4x5AvQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "img = np.zeros((512, 512, 3), np.uint8)\n",
    "img.fill(255)\n",
    "RecA = [20, 20, 300, 300]   # x1,y1,x2,y2\n",
    "RecB = [320, 320, 440, 440]\n",
    "drawIoU(RecA,RecB)\n",
    "img = np.zeros((512, 512, 3), np.uint8)\n",
    "img.fill(255)\n",
    "RecA = [1,160, 160, 280, 280]   # x1,y1,x2,y2\n",
    "RecB = [1,380, 380, 120, 120]\n",
    "drawCIoU(RecA,RecB)\n",
    "plt.imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bb2a1bf9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x2065c4626d0>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAC7CAYAAACend6FAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAavElEQVR4nO3de3SU9b3v8fc3ySTcwlVABERUQAEPKQZbcdflqRcQ5WK7UQRrEHeRLuuxnFYPFli0S121dnefnlW1Lioirm6lVLeLy9oaWFDUtmgMSrGAaETkkgCByKUEyCTzPX/kYRogIbeZXJ58XqysmfnN75n5/Sbf+fDM8zx5xtwdEREJl5TmHoCIiCSewl1EJIQU7iIiIaRwFxEJIYW7iEgIKdxFREIoaeFuZmPNbLuZFZjZnGQ9j0hTUl1La2HJOM7dzFKBT4GbgT3AB8Dd7r414U8m0kRU19KaJGvN/RqgwN13uHsZsBSYmKTnEmkqqmtpNZIV7n2B3VVu7wnaRFoz1bW0GmlJelyrpu2M7T9mNhOYCdCxY8err7jiiiQNRQQ2btx40N17NvJhaq1rUG1L09m5cycHDx6sri6TFu57gP5VbvcDCqt2cPeFwEKA7Oxsz8/PT9JQRMDMvkzAw9Ra16DalqaTnZ1d433J2izzATDIzAaaWTowBViRpOcSaSqqa2k1krLm7u7lZvYDIBdIBV509y31eYwYMUopxc/91CsNkEIKHeiAVbtlQeoiEXUNqu1EU21XL1mbZXD3/wb+uyHLxojxTPCvnPIEj6xtyiCDR3iE+7hPb4JGaExdg2o7GVTb1UtauDdGKaU8wzN8xmekkaZfWCPFiFFBBc/yLNOYRgYZzT2kNku1nViq7Zq1yHB3nHLKSSONl3iJK2JD4PhxaOtfLGIG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BWY2p7nH01hm1t/M/mRm28xsi5k9HLSH9kyDZpZqZh+Z2argdmjnWh+q7db/+27Vte3uzfYDpAKfA5cC6cDfgKHNOaYEzKkPMDK4ngl8CgwFngbmBO1zgF8E14cG884ABgavR2pzz6Oec/7fwCvAquB2aOdaj9dEtR2C33drru3mXnO/Bihw9x3uXgYspfLMe62Wuxe5+4fB9WPANipPLhXKMw2aWT/gNuCFKs2hnGs9qbZb+e+7tdd2c4d7nc6y11qZ2SXA14D3aeSZBluwXwOPArEqbWGda32Eeq6q7ZY/1+YO9zqdZa81MrNOwOtU/on60fN1raatVbwGZnY7cMDdN9Z1kWraWsVcGyC0c1VtV79INW3NOte6nvI3WUJ5lj0zi1BZ/P/p7v8VNO83sz7uXhSiMw1eB0wws3FAO6Czmf2ecM61vkI5V9V2K5prM++sSAN2ULkD4vROp2HNOaYEzMmAl4Ffn9X+S87cEfN0cH0YZ+6I2UEr2+kUzOMG/rnTKdRzreProdoOye+7tdZ2S3jhxlG51/1zYG5zjycB8/kXKj+ObQY2BT/jgB5Ufh/nZ8Fl9yrLzA3mvx24tbnn0MB5V30DhHqu9XhNVNsh+H231trWX6iKiIRQc+9QFRGRJFC4i4iEkMJdRCSEFO4iIiGkcBcRCSGFu4hICCncRURCSOEuIhJC/x8PRvqEatp+zwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "img = np.zeros((512, 512, 3), np.uint8)\n",
    "img.fill(255)\n",
    "RecA = [20, 20, 300, 300]   # x1,y1,x2,y2\n",
    "RecB = [30, 30, 250, 250]\n",
    "drawIoU(RecA,RecB)\n",
    "img = np.zeros((512, 512, 3), np.uint8)\n",
    "img.fill(255)\n",
    "RecA = [1,160, 160, 280, 280]   # x1,y1,x2,y2\n",
    "RecB = [1,140, 140, 220, 220]\n",
    "drawCIoU(RecA,RecB)\n",
    "plt.imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "28841c62",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x2065c520250>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAC7CAYAAACend6FAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAaWklEQVR4nO3de5BU5bnv8e8zMz3DbbiNoAioGAEFjBMYTIyJ5VGMCFswqXDESxxEQ4iXQzhuPahYJKWWGnd2ecqYuImKpPZWDjHbAqlNBgo3XhIEBsELjOAoCAjCAHIRkOmZfs4fvWh7oIe59Vx6ze9DdfXqt9fq9b49T/9YvdbqbnN3REQkXLJauwMiIpJ+CncRkRBSuIuIhJDCXUQkhBTuIiIhpHAXEQmhZgt3MxttZhvNrNzMZjTXekRakupaMoU1x3nuZpYNbAKuArYDq4Eb3H1D2lcm0kJU15JJmmvL/WKg3N0/dfdKYB4wvpnWJdJSVNeSMZor3PsC25Jubw/aRDKZ6loyRk4zPa6laKux/8fMpgBTADp37jzi/PPPb6auiMCaNWv2uHuvJj5MnXUNqm1pOVu2bGHPnj2p6rLZwn070D/pdj9gR/IM7j4bmA1QVFTkpaWlzdQVETCzz9LwMHXWNai2peUUFRXVel9z7ZZZDQw0swFmlgtMBBY207pEWorqWjJGs2y5u3uVmd0FlADZwAvuvr4hjxEjxhGO4Ce/65VGyCKLTnTCUu5ZkPpIR12DajvdVNupNdduGdz9v4D/asyyMWL8PvhXRVWae9Y+5ZHHvdzLrdyqF0ETNKWuQbXdHFTbqTVbuDfFEY7we37Px3xMDjn6gzVRjBjVVPMMz3ATN5FHXmt3qd1SbaeXart2bTLcHaeKKnLI4UVe5Hx0tkFT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Mz/G3gJWBTcDu1YG/CcqLZD8PfO5Npu7S33i4Fyd//U3SuBecS/eS9juftOd383mD4ElBH/cqlQftOgmfUDxgLPJTWHcqwNpNrO8L93ptd2a4d7vb5lL1OZ2TnAd4CVNPGbBtuwp4D7gFhSW1jH2hChHqtqu+2PtbXDvV7fspeJzKwL8FfiH1E/eKpZU7RlxHNgZv8E7Hb3NfVdJEVbRoy1EUI7VtV26kVStLXqWOv7lb/NJZTfsmdmEeLF/x/u/p9B8y4z6+PuO0P0TYOXAuPMbAzQAehqZv9OOMfaUKEcq2o7g8baygcrcoBPiR+AOH7QaWhr9ikNYzLgz8BTJ7Q/Sc0DMb8NpodS80DMp2TYQadgHJfzzUGnUI+1ns+Hajskf+9Mre228MSNIX7U/RPgwdbuTxrG8wPib8feB9YFlzFAAfHf4/w4uO6ZtMyDwfg3Ate09hgaOe7kF0Cox9qA50S1HYK/d6bWtj6hKiISQq19QFVERJqBwl1EJIQU7iIiIaRwFxEJIYW7iEgIKdxFREJI4S4iEkIKdxGREPr/czjSlN+5ROMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "img = np.zeros((512, 512, 3), np.uint8)\n",
    "img.fill(255)\n",
    "RecA = [20, 20, 300, 300]   # x1,y1,x2,y2\n",
    "RecB = [40, 40, 260, 260]\n",
    "drawIoU(RecA,RecB)\n",
    "img = np.zeros((512, 512, 3), np.uint8)\n",
    "img.fill(255)\n",
    "RecA = [1,160, 160, 280, 280]   # x1,y1,x2,y2\n",
    "RecB = [1,150, 150, 220, 220]\n",
    "drawCIoU(RecA,RecB)\n",
    "plt.imshow(img)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch",
   "language": "python",
   "name": "torch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
